package cn.wolfcode.wolf2w.web.controller;

import cn.wolfcode.wolf2w.domain.StrategyTheme;
import cn.wolfcode.wolf2w.query.StrategyThemeQuery;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.uitl.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyTheme")
public class StrategyThemeCatalogController {
    @Autowired
    private IStrategyThemeService strategyThemeService;
   
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyThemeQuery qo){
       Page<StrategyTheme> page =strategyThemeService.query(qo);
       model.addAttribute("page",page);
        //直接返回页面
        return "strategyTheme/list";
    }
    
    /**
     * 通过区域id删除数据
     * @par
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        strategyThemeService.delete(id);
        return JsonResult.success();
    }
   
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOUpdate(StrategyTheme strategyTheme){
        //NoNullStringUitl.getNull(strategyTheme.getSequence(),"");
        //直接返回页面
        if (StringUtils.hasLength(strategyTheme.getId())){
            //1先查询  2再替换  3修改
            //这个是特殊的类,
            strategyThemeService.update(strategyTheme);
        }else {
          strategyThemeService.save(strategyTheme);
        }
       return JsonResult.success();
    }
}
